package {
	import lovedna.framework.mvcs.Context;

	import net.lovedna.command.SystemStartCommand;
	import net.lovedna.data.request.RequestLogin;
	import net.lovedna.event.RequestEvent;
	import net.lovedna.event.SystemEvent;

	import flash.display.DisplayObjectContainer;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 * @author hi
	 */
	public class GameContext extends Context {
		private var _traceTxt : TextField;
		public function GameContext(container : DisplayObjectContainer) {
			super(container);
			container.stage.frameRate=80;
			_traceTxt = new TextField();
			container.addChild(_traceTxt);
			_traceTxt.multiline = true;
			_traceTxt.wordWrap = true;
			_traceTxt.mouseEnabled = false;
			_traceTxt.width = container.stage.stageWidth;
			container.stage.addEventListener(MouseEvent.CLICK, clickhandler);
			init();
		}

		private function clickhandler(event : MouseEvent) : void {
			var login : RequestLogin = new RequestLogin();
			login.uid = "liwei";
			login.pass = "123456";
			login.type = 0;
			dispatchEvent(new RequestEvent(login));
		}

		private function init() : void {
			addEventListener(SystemEvent.TRACE, tracehandler, true);
			mapCommand(SystemEvent.START, SystemStartCommand,SystemEvent,true);
			dispatchEvent(new SystemEvent(SystemEvent.START));
		}

		private function tracehandler(event : SystemEvent) : void {
			_traceTxt.htmlText = String(event.data);
		}
	}
}
